var a = require("../../../../@babel/runtime/helpers/toConsumableArray"), t = getApp(), e = 1;

Page({
    data: {
        order_field: "",
        order_by: "",
        coupon: "",
        zoneId: "",
        loading: !1,
        allLoaded: !1,
        datas: [],
        show: !1,
        inputs: "",
        id: "",
        classifyBol: !0,
        page: 1,
        type: null
    },
    onLoad: function(a) {
        try {
            var t = wx.getStorageSync("zoneId");
            t && this.setData({
                zoneId: t
            });
        } catch (a) {}
        if (a.id) try {
            this.setData({
                id: JSON.parse(a.id)
            });
        } catch (t) {
            this.setData({
                id: a.id
            });
        }
        a.coupon && this.setData({
            coupon: a.coupon
        }), a.type && this.setData({
            type: a.type
        }), a.keyword && this.setData({
            inputs: a.keyword
        }), a.order_field && this.setData({
            order_field: a.order_field
        }), a.order_by && this.setData({
            order_by: a.order_by
        }), this.gotoSearch(this.data.page, !0);
    },
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {
        if (console.log(this.data.allLoaded), this.data.allLoaded) console.log("没有更多数据"), 
        wx.showToast({
            title: "没有更多数据",
            icon: "none",
            duration: 1e3
        }); else {
            var a = this.data.page + 1;
            this.setData({
                page: a
            }), this.gotoSearch(a, !0);
        }
    },
    onShareAppMessage: function() {
        var a = "";
        return a += "?keyword=" + this.data.inputs, a += "&id=" + this.data.id, a += "&order_field=" + this.data.order_field, 
        a += "&order_by=" + this.data.order_by, a += "&coupon=" + this.data.coupon, {
            path: "/packageB/member/category/catelist/catelist" + (a += "&type=" + this.data.type)
        };
    },
    toggle: function(a) {
        var t = "";
        switch (a.currentTarget.dataset.idx) {
          case 1:
            this.setData({
                hascolor: 1,
                page: 1
            }), "1_2" == this.data.colorshow ? (this.setData({
                colorshow: "1_1"
            }), t = "comment_num", this.setData({
                order_field: t,
                order_by: "asc"
            })) : (this.setData({
                colorshow: "1_2"
            }), t = "comment_num", this.setData({
                order_field: t,
                order_by: "desc"
            }));
            break;

          case 2:
            this.setData({
                hascolor: 2,
                page: 1
            }), "2_2" == this.data.colorshow ? (this.setData({
                colorshow: "2_1"
            }), t = "show_sales", this.setData({
                order_field: t,
                order_by: "asc"
            })) : (this.setData({
                colorshow: "2_2"
            }), t = "show_sales", this.setData({
                order_field: t,
                order_by: "desc"
            }));
            break;

          case 3:
            this.setData({
                hascolor: 3,
                page: 1
            }), "3_2" == this.data.colorshow ? (this.setData({
                colorshow: "3_1"
            }), t = "price", this.setData({
                order_field: t,
                order_by: "asc"
            })) : (this.setData({
                colorshow: "3_2"
            }), t = "price", this.setData({
                order_field: t,
                order_by: "desc"
            }));
        }
        0 != this.data.datas.length && (this.setData({
            datas: []
        }), console.log(this.data.page), this.gotoSearch(this.data.page));
    },
    gotoSearch: function(e, o) {
        var s = this, d = null;
        "snatchRegiment" == this.data.type ? (d = t.getNetAddresss("plugin.snatch-regiment.api.index.getSnatchData"), 
        d += "&art=catGoods") : d = t.getNetAddresss("goods.goods.search-goods"), d += "&search[keyword]=" + this.data.inputs, 
        d += "&page=" + e, d += "&search[category]=" + this.data.id, d += "&order_field=" + this.data.order_field, 
        d += "&order_by=" + this.data.order_by, d += "&search[couponid]=" + this.data.coupon, 
        d += "&search[as_id]=" + this.data.zoneId, t._getNetWork({
            showToastIn: !1,
            url: d,
            success: function(t) {
                var e = t.data;
                if (1 == e.result) {
                    s.data.loading = !1, s.data.allLoaded = !1;
                    var d = "snatchRegiment" == s.data.type ? e.data.catGoods.goods.data : e.data.data;
                    if (d.length <= 0) return s.data.loading = !0, void (s.data.allLoaded = !0);
                    if (console.log(e.data), "snatchRegiment" == s.data.type && e.data.catGoods.goods.current_page > e.data.catGoods.goods.last_page) return s.data.loading = !0, 
                    void (s.data.allLoaded = !0);
                    var i = [];
                    if (o) {
                        var r, n;
                        if (i = s.data.datas, "snatchRegiment" == s.data.type) (r = i).push.apply(r, a(e.data.catGoods.goods.data)); else (n = i).push.apply(n, a(e.data.data));
                        s.setData({
                            show: "02" != e.data.goods_template
                        });
                    } else {
                        i = "snatchRegiment" == s.data.type ? e.data.catGoods.goods.data : e.data.data;
                        try {
                            s.setData({
                                goods_template: e.data.goods_template,
                                goods_style_set: e.data.goods_style_set,
                                show: "02" != e.data.goods_template
                            });
                        } catch (a) {
                            console.log(a);
                        }
                    }
                    for (var h = 0; h < i.length; h++) console.log(parseInt(Number(0 == i[h].market_price))), 
                    parseInt(Number(0 == i[h].market_price)) ? i[h].notMarket_price = 0 : i[h].notMarket_price = 1;
                    if (s.setData({
                        datas: i
                    }), e.data.current_page >= e.data.last_page) return s.data.loading = !0, void (s.data.allLoaded = !0);
                    if (d.length < 10) return s.data.loading = !0, void (s.data.allLoaded = !0);
                } else s.setData({
                    datas: []
                }), s.data.loading = !0, s.data.allLoaded = !0;
            },
            fail: function(a) {}
        });
    },
    classifyBolbtn: function() {
        this.data.show ? this.setData({
            show: !1,
            classifyBol: !0
        }) : this.setData({
            show: !0,
            classifyBol: !1
        });
    },
    inpbtn: function(a) {
        var t = a.detail.value;
        this.setData({
            inputs: t
        });
    },
    inpbtnclear: function() {
        this.setData({
            inputs: ""
        });
    },
    search: function() {
        e = 1, this.setData({
            datas: []
        }), this.gotoSearch(e, !1);
    }
});